package shuzi.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.shuzi.offer.R;

/**
 * topBar
 * 
 * @author lung 上午12:21:54 2013
 */
public class TopBarRelativeLayout extends RelativeLayout implements
		View.OnClickListener {

	/** 今日推荐 */
	private Button recommendToady = null;
	/** 新品上市 */
	private Button newArrival = null;
	/** 其他品牌 */
	public Button otherBrands = null;
	/** 扩展 */
	private LayoutInflater inflater = null;
	/** 布局view */
	private View view = null;
	/** 监听器 */
	private OnBarClickListener onBarClickListener = null;

	public TopBarRelativeLayout(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		initLayout(context);
	}

	public TopBarRelativeLayout(Context context, AttributeSet attrs) {
		this(context, attrs, 0);

	}

	public TopBarRelativeLayout(Context context) {
		this(context, null);

	}

	/**
	 * 初始化布局
	 * 
	 * @param context
	 */
	private void initLayout(Context context) {
		inflater = LayoutInflater.from(context);
		view = inflate(context, com.shuzi.offer.R.layout.top_bar, null);
		recommendToady = (Button) view.findViewById(R.id.recommendToady);
		newArrival = (Button) view.findViewById(R.id.newArrival);
		otherBrands = (Button) view.findViewById(R.id.otherBrands);

		// 设置监听器
		recommendToady.setOnClickListener(this);
		newArrival.setOnClickListener(this);
		otherBrands.setOnClickListener(this);

		addView(view,new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.titleBarHeight)));

	}

	public void setOnBarClickListener(OnBarClickListener onBarClickListener) {
		this.onBarClickListener = onBarClickListener;
	}

	@Override
	public void onClick(View v) {
		onBarClickListener.onBarClick(v.getId());
	}

	/**
	 * 声明一个接口
	 * 
	 * @author lung 上午12:40:33 2013
	 */
	public interface OnBarClickListener {

		public void onBarClick(int id);

	}

}
